home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
os2
/
yeah09.zip
/
yea.h
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-25
|
17KB
|
618 lines
#ifndef YEA_H
#define YEA_H
//------------------------------------------------------------
//
// Name: yea.h
// Version: 0.9
// Author: Björn Fahller.
//
// Copyright (C) Björn Fahller, 1996.
//
// Purpose: All necessary declarations for YEAH, both the base
// functionality (class EA and TEA<T>) and the provided
// implementations of StringEA, SequenceEA and
// TSequenceEA<T>
//
// History:
// Ver. Date What
// 0.9 1996-05-26 First official release.
//
//------------------------------------------------------------
class fstreambase;
struct _EAOP2;
#include <IString.hpp>
#include <IMap.h>
#include <IKSSet.h>
#include <ISeq.h>
#include <IPtr.h>
#include <IExcept.hpp>
#include <strstrea.h>
IEXCLASSDECLARE(EAError, IException);
IEXCLASSDECLARE(EAReadError, EAError);
IEXCLASSDECLARE(EAWriteError, EAError);
IEXCLASSDECLARE(EATypeMismatchError, EAError);
IEXCLASSDECLARE(EATSeqeuceEAInstError,EATypeMismatchError);
class EA
{
public:
typedef unsigned short Identifier;
struct CreatorIdPair;
typedef IMap<CreatorIdPair, Identifier> CreatorMap;
typedef EA* (*Creator)(istrstream&, CreatorMap*);
struct CreatorIdPair {
Creator c;
Identifier id;
IMngPointer<CreatorMap> pSubMap;
CreatorIdPair(const Creator& cc, Identifier i) : c(cc), id(i) {};
IBoolean operator==(const CreatorIdPair& i) const { return id == i.id; };
IBoolean operator<(const CreatorIdPair& i) const { return id < i.id; };
};
static CreatorMap defaultCreatorMap;
typedef enum { optional = 0, mandatory = 0x80 } Flagset;
struct Name {
IString name;
Flagset flags;
Name(const IString& n, Flagset f) : name(n), flags(f) {};
IBoolean operator==(const Name& n) const { return name == n.name; };
IBoolean operator<(const Name& n) const { return name < n.name; };
};
typedef IKeySortedSet<Name, IString> NameSet;
typedef enum {
ReadError,
WriteError,
NoSuchEAError,
TypeMismatchError
} Error;
typedef void (*ErrorHandler)(Error, unsigned long);
static ErrorHandler errorHandler;
static NameSet namesIn(const IString& file);
static NameSet namesIn(fstreambase& file);
virtual ~EA(void);
Identifier attributeId(void) const { return id; };
Flagset getFlags(void) const { return (Flagset)flags;};
void setFlags(Flagset f) { flags = (char)f; };
static EA* newFrom(const IString& file,
const IString& name,
const CreatorMap& = defaultCreatorMap);
static EA* newFrom(fstreambase& file,
const IString& name,
const CreatorMap& = defaultCreatorMap);
static void remove(const IString& file, const IString& name);
static void remove(fstreambase& file, const IString& name);
void getFrom(const IString& file, const IString& name);
void getFrom(fstreambase& file, const IString& name);
void storeTo(const IString& file, const IString& name);
void storeTo(fstreambase& file, const IString& name);
virtual EA* clone(void) const = 0;
virtual void setCreatorMap(const CreatorMap*) {};
protected:
EA(Identifier anId);
EA(const EA&);
const EA& operator=(const EA&);
static istrstream& read(EA* pea, istrstream& is)
{ return pea->readFrom(is);};
static ostrstream& write(EA* pea, ostrstream& os)
{ return pea->writeTo(os);};
virtual istrstream& readFrom(istrstream&) = 0;
virtual ostrstream& writeTo(ostrstream&) = 0;
private:
void setupFEA(const IString&);
void feaproc(void);
Identifier id;
_EAOP2* peaop2;
char flags;
friend EA* createFrom(_EAOP2*, const EA::CreatorMap&);
};
template <class T, EA::Identifier eaid>
class TEA : public EA
{
public:
enum { id = eaid };
static T* cast(EA*);
static const T* cast(const EA*);
virtual ~TEA(void) {};
static void allowDynamic(EA::CreatorMap* pCM = &EA::defaultCreatorMap,
const EA::Creator& creator = createFrom);
static void disallowDynamic(EA::CreatorMap* pCM = &EA::defaultCreatorMap);
protected:
TEA(void) : EA(eaid) {};
TEA(const TEA<T, eaid>&t) : EA(t) {};
const TEA<T, eaid>& operator=(const TEA<T, eaid>& t)
{ EA::operator=(t); return *this;};
private:
static EA* createFrom(istrstream&, EA::CreatorMap*);
static NameSet namesIn(const IString& file);
static NameSet namesIn(fstreambase& file);
static EA* newFrom(const IString& file,
const IString& name,
const CreatorMap& = defaultCreatorMap);
static EA* newFrom(fstreambase& file,
const IString& name,
const CreatorMap& = defaultCreatorMap);
static void remove(const IString& file, const IString& name);
static void remove(fstreambase& file, const IString& name);
static istrstream& read(EA*,istrstream&);
static ostrstream& write(EA*,ostrstream&);
class Creator {};
class CreatorMap {};
class CreatorIdPair {};
class Name {};
class Error {};
class ErrorHandler {};
class Flagset {};
class Identifier {};
class NameSet {};
};
class StringEA : public TEA<StringEA, 0xfffd>,
public IString
{
public:
StringEA(void) : IString() {};
StringEA(const void* pBuffer, unsigned lenBuffer, char padCharacter = ' ')
: IString(pBuffer, lenBuffer, padCharacter) {};
StringEA(const IString& s) : IString(s) { };
StringEA(int i) : IString(i) { };
StringEA(unsigned u) : IString(u) { };
StringEA(double d) : IString(d) { };
StringEA(char c) : IString(c) { };
StringEA(unsigned char uc) : IString(uc) { };
StringEA(signed char sc) : IString(sc) { };
StringEA(const char* p) : IString(p) { };
StringEA(const unsigned char* p) : IString(p) { };
StringEA(const signed char* p) : IString(p) { };
StringEA(const void* pBuffer1, unsigned lenBuffer1,
const void* pBuffer2, unsigned lenBuffer2,
char padCharacter = ' ') : IString(pBuffer1, lenBuffer1,
pBuffer2, lenBuffer2,
padCharacter) {};
StringEA(const void* pBuffer1, unsigned lenBuffer1,
const void* pBuffer2, unsigned lenBuffer2,
const void* pBuffer3, unsigned lenBuffer3,
char padCharacter = ' ') : IString(pBuffer1, lenBuffer1,
pBuffer2, lenBuffer2,
pBuffer3, lenBuffer3,
padCharacter) {};
StringEA(const StringEA& s) : TEA<StringEA, StringEA::id>(s), IString(s) {};
virtual ~StringEA(void) {};
const StringEA& operator=(const StringEA& s)
{
TEA<StringEA, StringEA::id>::operator=(s);
IString::operator=(s);
return *this;
};
const StringEA& operator=(const IString& s)
{
IString::operator=(s);
return *this;
};
StringEA(const IString& filename, const IString& eaname)
{ getFrom(filename, eaname);};
StringEA(fstreambase& file, const IString& eaname)
{ getFrom(file, eaname); };
virtual StringEA* clone(void) const;
protected:
virtual istrstream& readFrom(istrstream&);
virtual ostrstream& writeTo(ostrstream&);
private:
};
class MTSequenceEA : public TEA< MTSequenceEA, 0xffdf>,
public ISequence<EA*>
{
public:
typedef EA* (*ErrorFunction)(EA::Identifier);
static ErrorFunction errorFunction;
MTSequenceEA(const EA::CreatorMap* = &EA::defaultCreatorMap);
MTSequenceEA(const MTSequenceEA& mvea);
MTSequenceEA(const ISequence<EA*>&,
const EA::CreatorMap* = &EA::defaultCreatorMap);
MTSequenceEA(const IString& filename,
const IString& eaname,
const EA::CreatorMap* = &EA::defaultCreatorMap);
MTSequenceEA(fstreambase& file,
const IString& eaname,
const EA::CreatorMap* = &EA::defaultCreatorMap);
const MTSequenceEA& operator=(const MTSequ